<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    (function(){
        function Look(){
            this.shuju={
                // 'keji':[function(){},function(){}]
            }
             
            //         消息类型"字符串"    接受消息的函数"function"
            this.dingyue=function(type,handler){
                //订阅消息
                //保存消息类型及函数
                this.shuju[type] = this.shuju[type] || [];
                this.shuju[type].push( handler ); 
            }
            this.fabu=function(type,msg){
                //发布消息

                this.shuju[type] &&
                    this.shuju[type].forEach((item)=>{ //遍历并调用每个回调函数
                        item(msg);
                    })
            }
            
        }
        window.Look=Look
    })()


    //实例化对象
      let os=new Look()



      //订阅消息
      os.dingyue('keji',function(msg){
        //接受发布者的消息
        console.log('2215收到了来自keji的消息'+msg);
      })
      //订阅消息
      os.dingyue('keji',function(msg){
        //接受发布者的消息
        console.log('2216收到了来自keji的消息'+msg);
      })

      //订阅消息
      os.dingyue('keji',function(msg){
        //接受发布者的消息
        console.log('2217收到了来自keji的消息'+msg);
      })




      //发布消息
      os.fabu('keji','准时上课')
</script>